/**
 * 用户列表
 *
 * @author liuxiaotang
 */
define(["app", "comm/pager/PagerControl", "js/services/MessageBox", "js/services/MuseService"], function (app) {

    var deps = ["$scope", "$state", "$modal", "MessageBox", "MuseService"];

    function controller ($scope, $state, $modal, MessageBox, MuseService) {
        //初始化查询对象 和 分页对象
        app.regsiterCacheData($scope, $state);
        $scope.queryObj = $scope.queryObj || {};
        $scope.pagerObj = $scope.pagerObj || {};

        //获取列表
        $scope.getObjList = function (pageNo, pageSize) {
            var curPage = pageNo || $scope.pagerObj.currentPage || 1;
            var param = {
                page: curPage,
                pageSize: pageSize || $scope.pagerObj.pageSize,
                username: $scope.queryObj.userName,
                roleId: $scope.queryObj.adminRoleId
            }
            // if ($scope.queryObj.userName) {
            //     param += '$$userName--' + $scope.queryObj.userName;
            // }
            // if ($scope.queryObj.contact != undefined) {
            //     param += '$$contact--' + $scope.queryObj.contact;
            // }
            // if ($scope.queryObj.adminRoleId != undefined) {
            //     param += '$$adminRoleId--' + $scope.queryObj.adminRoleId;
            // }

            MuseService.post(baseServices_restfulUrl + "admin/adminuser/findUsers.json", param).success(
                function (data, status, headers, config) {
                    // console.log(data);
                    if (data.state == 0) {
                        $scope.userList = data.data.data;

                        //分页器
                        $scope.pagerObj = PageCtrl().page($scope.pagerObj, data.totalPage, curPage);
                    }
                });
        };

        $scope.getObjList();

        //获取“选择角色”下拉框数据
        $scope.getAdminRoleList = function () {
            MuseService.post(baseServices_restfulUrl + "admin/adminrole/list.json").success(
                function (data, status, headers, config) {
                    if (data.state == 0) {
                        $scope.adminRoleList = data.data;
                    } else {
                        MessageBox.notify('获取列表失败:' + data.message);
                    }
                });
        };
        $scope.getAdminRoleList();

        // //重置查询表单
        // $scope.resetParam = function () {
        //     app.regsiterCacheData($scope,$state);$scope.queryObj = $scope.queryObj ||{};
        //     $scope.getObjList();
        // };

        //新增
        $scope.add = function () {
            $state.go('adminuserEdit');
        };

        //编辑
        $scope.edit = function (id) {
            $state.go('adminuserEdit', {userId: id});
        };

        $scope.pageChanged = function () {
            PageCtrl().check($scope.pagerObj);
            $scope.getObjList($scope.pagerObj.currentPage, $scope.pagerObj.pageSize);
        }
    }

    controller.$inject = deps;
    app.lazy.controller("AdminUserListController", controller);
});
